package com.cnaaa.xinqiao.controller;

import com.cnaaa.xinqiao.service.ChartsService;
import com.cnaaa.xinqiao.vo.BasicJsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;
import java.util.Map;

/**
 * 2018/10/22 Create by 郭文梁
 * ChartsDataController
 * 如表数据访问控制器
 *
 * @author 郭文梁
 * @date 2018/10/22
 */
@RestController
@RequestMapping("/data")
public class ChartsDataController {
    private final ChartsService chartsService;

    @Autowired
    public ChartsDataController(ChartsService chartsService) {
        this.chartsService = chartsService;
    }

    @GetMapping("/district-score")
    public BasicJsonResult<Map<String, Integer>> districtScore() {
        return BasicJsonResult.ok(chartsService.getDistrictScore());
    }

    @GetMapping("/overview")
    public BasicJsonResult<Map<String, Object>> overView() {
        Date date = new Date();
        return BasicJsonResult.ok(chartsService.overView(date));
    }

    @GetMapping("/district-people-count")
    public BasicJsonResult<Map<String, Integer>> districtPeopleCount() {
        return BasicJsonResult.ok(chartsService.districtPeopleCount());
    }

    @GetMapping("/sales-volume")
    public BasicJsonResult<Map<Integer, Integer>> salesVolume(Integer year) {
        return BasicJsonResult.ok(chartsService.salesVolume(year));
    }

    @GetMapping("/sales-count")
    public BasicJsonResult<Map<Integer, Integer>> salesCount(Integer year) {
        return BasicJsonResult.ok(chartsService.salesCount(year));
    }

    @GetMapping("/score-increment")
    public BasicJsonResult<Map<String, Map<Integer, Integer>>> scoreIncrement(Integer year) {
        return BasicJsonResult.ok(chartsService.scoreIncrement(year));
    }

    @GetMapping("/score-distribution")
    public BasicJsonResult<Map<String, Map<String, Object>>> scoreDistribution() {
        return BasicJsonResult.ok(chartsService.scoreDistribution());
    }
}
